﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ReconUI
{
    public partial class ForgotPasswordPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           Label lblDateTime = ((Label)Master.FindControl("lblDateTime"));
            lblDateTime.Visible = false;
        }//PasswordRecovery1_VerifyingUser
       

        protected void PasswordRecovery1_VerifyingUser(object sender, LoginCancelEventArgs e)
        {
           
            DBFactory db = new DBFactory();
           // string userName = db.GetUserSpecificDetails(PasswordRecovery1.UserName);
            UserVO user = db.GetUserDetails(PasswordRecovery1.UserName);
           // if (!userName.Equals(string.Empty))
            if(user != null)
            {
                //Response.Redirect("~/ReconSignIn.aspx");
               // UserVO user = new UserVO();
                user.isFourcePwdChange = "Y";
                user.userId = PasswordRecovery1.UserName;
                //Genrate password according to policy 
                string tempPwd = "gH&12!";
                db.setForcePwdChange(user, tempPwd);// we can do in single function, where we need to check user avlb & change force flag
                Utils.sendEmail("your password is " + tempPwd, "Recon new password.", user.emailId);
                e.Cancel = true;
                SignInLink.Text = "Sign In";
                SignInLink.Visible = true;
                SignInLink.NavigateUrl = "ReconSignIn.aspx";
                lblErrorMsg.Text = "* Details has been sent.";
                lblErrorMsg.ForeColor = System.Drawing.Color.Red;
                
            }
            else
            {
                //System.Drawing.ColorTranslator.FromHtml("#22FF99");
                e.Cancel = true;
                SignInLink.Visible = false;
                lblErrorMsg.Text = "* Invalid user " + user.userId;
                lblErrorMsg.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
}